/*
 * Copyright 2020 edenrun.cn All right reserved. This software is the
 * confidential and proprietary information ofedenrun.cn ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with edenrun.cn.
 */

package com.zoom.pluto.smf.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类
 *
 * @author zoom
 * @date 2020-06-05
 */
@Configuration
@EnableSwagger2
@Conditional(SwaggerCondition.class)
public class SwaggerConfiguration {

    /**
     * 用来创建该Api的基本信息 （这些基本信息会展现在文档页面中）
     **/
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("SMF服务对接接口").description("SMF提供中医综合诊断系统对接服务").termsOfServiceUrl("http://blog.didispace.com/").version("1.0.0").build();
    }

    /**
     * 函数创建Docket的Bean
     * <p>select()函数返回一个ApiSelectorBuilder实例用来控制哪些接口暴露给Swagger来展现， 本例采用指定扫描的包路径来定义</p>
     * <p>Swagger会扫描该包下所有Controller定义的API， 并产生文档内容（除了被@ApiIgnore指定的请求）</p>
     **/
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().paths(PathSelectors.any()).apis(RequestHandlerSelectors.basePackage("com.zoom.pluto.smf.controller")).build();
    }

}
